package com.janko.redislock.demo;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author nyk
 * @Date 2021/6/21 9:32
 * @Version 1.0
 * @Desc 发布订阅模式- 发布者
 */
@RestController
public class PublishController {

    private RedisTemplate<String, String> redisTemplate;

    public PublishController(RedisTemplate<String, String> redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    /**
     * 发布者通过接口生产消息
     * @param message
     */
    @GetMapping("/publish")
    public void publish(@RequestParam String message) {
        // 发送消息
        redisTemplate.convertAndSend(NoticeConst.CHANNEL, message);
    }
}
